package cn.edu.ujn.ch17.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.ujn.ch17.dao.Customer;
import cn.edu.ujn.ch17.service.ICustomerService;

@Controller
public class CustomerController {
    @Autowired
	private ICustomerService customerService;

    @RequestMapping("/customer/{id}")
    public String find(@PathVariable("id") int id,Model model) {
        Customer customer = customerService.findById(id);
        model.addAttribute("customer", customer);
        return "customer";
    	
    }
    @GetMapping("/add")
    public String toadd() {
    	return "addCustomer";
    }
    @RequestMapping("/addCustomer")
    public String add(Customer customer) {
    	Customer add = this.customerService.add(customer);
    	return "customer";
    }
    @RequestMapping("/findAll")
    public String findAll(Model model) {
    	List<Customer> findAll = this.customerService.findAll();
    	model.addAttribute("list", findAll);
    	return "listCustomer";
    	
    	
    }
}
